package com.zc.core;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

/**
 * @author xiepufeng
 * 获取协议支持扩展数据
 */
@Data
public class ProtocolStandbyValue {

    private Map<String, Cell> value = new HashMap<>();

    public ProtocolStandbyValue() {

    }

    public ProtocolStandbyValue(String value) {
        this.value = JSON.parseObject(value, (Type)Map.class);
    }

    public ProtocolStandbyValue(Map<String, Cell> value) {
        this.value = value;
    }

    @Data
    public static class Cell {
        /**
         * 协议支持扩展数据 id
         */
        public String id;

        /**
         * 物模型 id
         */
        public String thingId;

        public JSONObject expands;
    }

    public String toJSONString() {
        return JSON.toJSONString(value);
    }

    public void pushCell(Cell cell) {
        value.put(cell.id, cell);
    }

}
